# -*- coding: utf-8 -*-
'''
@author: olivia.dou
Created on: 2022/12/20 10:12
desc: 企业微信登录页 v4.0.19
'''
from appium.webdriver.common.appiumby import AppiumBy
import logging
from base.get_config import get_other_app_activity
from base.po.mobile_base_page import MobileBasePage
from proj_spec.CLUE.mobile_po.wechat_login_page import WechatLoginPage


class WeworkLoginPage(MobileBasePage):
    _login_by_wechat_locator = (AppiumBy.XPATH, "//*[@resource-id='com.tencent.wework:id/abr']") # 微信登录按钮
    _agree_check_locator = (AppiumBy.XPATH, "//*[@resource-id='com.tencent.wework:id/nc']")
    _agree_btn_locator = (AppiumBy.XPATH, "//*[@resource-id='com.tencent.wework:id/cja']") #同意协议和隐私

    def login_by_wechat(self):
        if self.driver.is_app_installed(get_other_app_activity()[0]):
            self.find_element_and_click(self._agree_check_locator)
            self.find_element_and_click(self._login_by_wechat_locator)

            ## Switch to the app specifued under otherApps capability by adding AppPackage & AppActivity.
            # self.driver.start_activity(*get_other_app_activity())
            wechat_login_page = WechatLoginPage(self.driver)
            wechat_login_page.login()
            return True
        else:
            logging.error("wechat not installed")
            return False



